﻿namespace Blaze.UI
{
    using UnityEngine;
    using UnityEngine.UI;

    public class ScreenBlurGraphic : Graphic
    {
        public override Texture mainTexture
        {
            get
            {
                if (!Application.isPlaying)
                    return null;
                return ScreenBlurSource.Instance.BlurredScreen;
            }
        }

        protected ScreenBlurGraphic()
        {
            useLegacyMeshGeneration = false;
        }

        protected override void OnEnable()
        {
            if (Application.isPlaying)
            {
                var rootCanvas = canvas.rootCanvas;
                rootCanvas.enabled = false;
                ScreenBlurSource.Instance.Capture();
                rootCanvas.enabled = true;
            }
            base.OnEnable();
        }
    }
}